package cn.tedu.boyou.acticle.service.impl;

import cn.tedu.boyou.acticle.domain.Answering;
import cn.tedu.boyou.acticle.mapper.AnsweringMapper;
import cn.tedu.boyou.acticle.service.IAnsweringService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@Service
public class AnsweringServiceImpl implements IAnsweringService {
    @Autowired
    private AnsweringMapper mapper;

    public Long insert(Answering queanser) {
        queanser.setCreateTime(new Date());
        mapper.insert(queanser);
        System.out.println(queanser.getId());
        return queanser.getId();
    }

    public Answering get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<Long> listAll(int type) {
        String t = "";
        if(type == 1){
            t += "createTime";
        }
        return mapper.getAll(t);
    }

    public void update(Long answerId) {
        Answering answering = mapper.selectByPrimaryKey(answerId);
        answering.setState(1);
        mapper.updateByPrimaryKey(answering);
    }

    public List<Answering> getlist() {

        return mapper.ListAll(Answering.STATE_UNANSWERED);
    }

    public List<Answering> selectList() {
        return mapper.selectAll();
    }

    public void updateViewnum(Answering answering) {
        mapper.updateByPrimaryKey(answering);
    }
}
